// 滚动动画实现
document.addEventListener('DOMContentLoaded', function () {
    // 获取所有需要动画的元素
    const animatedElements = document.querySelectorAll('.section-animate');

    // 检查元素是否在视口中
    function isInViewport(element) {
        const rect = element.getBoundingClientRect();

        return (
            rect.top <= (window.innerHeight || document.documentElement.clientHeight) * 0.75 &&
            rect.bottom >= 0
        );
    }

    // 处理滚动事件
    function handleScroll() {
        animatedElements.forEach(element => {


            if (isInViewport(element)) {
                element.classList.add('section-visible');
            }
        });
    }

    // 初始检查
    handleScroll();

    // 监听滚动事件
    window.addEventListener('scroll', handleScroll);


    // 修复后的导航栏滚动效果代码
    window.addEventListener('scroll', function () {
        const headers = document.getElementsByClassName('m-nav');

        if (headers.length > 0) {
            const header = headers[0];
            if (window.scrollY > 100) {
                header.style.background = '#fff';
                header.classList.add('scrolled'); // 添加scrolled类
                header.style.boxShadow = '0 2px 10px rgba(0,0,0,0.1)';
            } else {
                header.style.background = 'rgba(255, 255, 255, 0.2)'; // 更透明的初始状态
                header.style.boxShadow = 'none';
                header.classList.remove('scrolled'); // 添加scrolled类
            }
        }
    });
    // 平滑滚动
    document.querySelectorAll('a[href^="#"]').forEach(anchor => {
        anchor.addEventListener('click', function (e) {
            e.preventDefault();

            const targetId = this.getAttribute('href');
            const targetElement = document.querySelector(targetId);

            if (targetElement) {
                window.scrollTo({
                    top: targetElement.offsetTop - 90,
                    behavior: 'smooth'
                });
            }
        });
    });
    // 数字动画函数
    function animateNumber(element) {
        const target = parseInt(element.getAttribute('data-target'));
        const duration = 500; // 动画时长(毫秒)
        const frameDuration = 1000 / 60; // 每帧时长(约60fps)
        const totalFrames = Math.round(duration / frameDuration);
        let frame = 0;
        const current = parseInt(element.textContent);

        // 如果已经在动画中或已经完成，则跳过
        if (element.classList.contains('animating')) return;
        element.classList.add('animating');

        const counter = setInterval(() => {
            frame++;
            const progress = frame / totalFrames;
            const currentValue = Math.round(target * progress);

            element.textContent = currentValue;

            if (frame >= totalFrames) {
                clearInterval(counter);
                element.textContent = target;
                element.classList.remove('animating');
            }
        }, frameDuration);
    }

    // 检查数字元素是否在视口中
    function checkNumbers() {
        document.querySelectorAll('.count-number').forEach(num => {
            if (isInViewport(num.closest('li'))) {
                animateNumber(num);
            }
        });
    }

    // 修改原有的handleScroll函数
    function handleScroll() {
        // 原有元素动画逻辑
        animatedElements.forEach(element => {
            if (isInViewport(element)) {
                element.classList.add('section-visible');
            }
        });

        // 新增数字动画检查
        checkNumbers();
    }

    // 初始检查
    handleScroll();
});
 // 客户logo轮播
        var clientLogoSwiper = new Swiper('.client-logo-swiper', {
            loop: true,
            slidesPerView: 5,
            spaceBetween: 20,
            navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev',
            },
            breakpoints: {
                1024: {
                    slidesPerView: 4,
                },
                768: {
                    slidesPerView: 3,
                },
                480: {
                    slidesPerView: 2,
                }
            }
        });
